{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'name': 'Alice', 'age': 25}\n"
     ]
    }
   ],
   "source": [
    "def example_function():\n",
    "    name = \"Alice\"\n",
    "    age = 25\n",
    "    \n",
    "    print(locals())\n",
    "\n",
    "example_function()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/wlc/miniconda3/envs/learning_to_adapt/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_qint8 = np.dtype([(\"qint8\", np.int8, 1)])\n",
      "/home/wlc/miniconda3/envs/learning_to_adapt/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_quint8 = np.dtype([(\"quint8\", np.uint8, 1)])\n",
      "/home/wlc/miniconda3/envs/learning_to_adapt/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:528: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_qint16 = np.dtype([(\"qint16\", np.int16, 1)])\n",
      "/home/wlc/miniconda3/envs/learning_to_adapt/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:529: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_quint16 = np.dtype([(\"quint16\", np.uint16, 1)])\n",
      "/home/wlc/miniconda3/envs/learning_to_adapt/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:530: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  _np_qint32 = np.dtype([(\"qint32\", np.int32, 1)])\n",
      "/home/wlc/miniconda3/envs/learning_to_adapt/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:535: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.\n",
      "  np_resource = np.dtype([(\"resource\", np.ubyte, 1)])\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "WARNING:tensorflow:From /home/wlc/miniconda3/envs/learning_to_adapt/lib/python3.7/site-packages/tensorflow/python/framework/op_def_library.py:263: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.\n",
      "Instructions for updating:\n",
      "Colocations handled automatically by placer.\n"
     ]
    }
   ],
   "source": [
    "import tensorflow as tf\n",
    "\n",
    "#变量\n",
    "tf.Variable(tf.random_normal([3, 2], stddev=0.1, name=\"weights\"))\n",
    "\n",
    "#常量\n",
    "x = tf.constant(13)\n",
    "\n",
    "#占位符\n",
    "\n",
    "x = tf.placeholder(\"float\", shape=None)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "40\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2023-07-17 09:13:21.871405: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 AVX512F FMA\n",
      "2023-07-17 09:13:21.879831: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 3600000000 Hz\n",
      "2023-07-17 09:13:21.880442: I tensorflow/compiler/xla/service/service.cc:150] XLA service 0x2a954d0 executing computations on platform Host. Devices:\n",
      "2023-07-17 09:13:21.880464: I tensorflow/compiler/xla/service/service.cc:158]   StreamExecutor device (0): <undefined>, <undefined>\n"
     ]
    }
   ],
   "source": [
    "# 计算图\n",
    "\n",
    "A = tf.multiply(8, 5)\n",
    "\n",
    "B = tf.multiply(A, 1)\n",
    "\n",
    "# 会话\n",
    "\n",
    "sess = tf.Session()\n",
    "\n",
    "print(sess.run(B))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### TensorBoarrd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "26\n"
     ]
    }
   ],
   "source": [
    "\n",
    "a = tf.constant(5)\n",
    "b = tf.constant(4)\n",
    "c = tf.multiply(a,b)\n",
    "d = tf.constant(2)\n",
    "e = tf.constant(3)\n",
    "f = tf.multiply(d,e)\n",
    "g = tf.add(c,f)\n",
    "\n",
    "def tensorboard(target):\n",
    "    with tf.Session() as sess:\n",
    "        writer = tf.summary.FileWriter(\"output\", sess.graph)\n",
    "        print(sess.run(target))\n",
    "        writer.close()\n",
    "\n",
    "tensorboard(g)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 范围"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "26\n"
     ]
    }
   ],
   "source": [
    "with tf.name_scope(\"Computation\"):\n",
    "    with tf.name_scope(\"Part1\"):\n",
    "        a = tf.constant(5)\n",
    "        b = tf.constant(4)\n",
    "        c = tf.multiply(a,b)\n",
    "    with tf.name_scope(\"Part2\"):\n",
    "        d = tf.constant(2)\n",
    "        e = tf.constant(3)\n",
    "        f = tf.multiply(d,e)\n",
    "with tf.name_scope(\"Result\"):\n",
    "    g = tf.add(c,f)\n",
    "\n",
    "tensorboard(g)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.16"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
